/**
 * 
 */
package ma.hamada.swing;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;

import ma.hamada.controller.PieceController;
import ma.hamada.event.PositionChangedEvent;
import ma.hamada.model.PiecePosition;
import ma.hamada.view.PieceView;

/**
 * @author M.ABDELOUHAB
 * 
 */
public class JPieceView extends PieceView implements ActionListener {

	JButton button = null;
	PiecePosition piecePosition;

	public JPieceView(PieceController controller) {
		this(controller, "");
	}

	public JPieceView(PieceController controller, String value) {
		super(controller);
		
			button = new JButton();
			ImageIcon icon = new ImageIcon("images\\" + value + ".png");
			button.setIcon(icon);
			button.setSize(100, 100);
			button.setBorderPainted(false);
//			button.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
			button.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		getController().notifyPositionChanged(e);
	}

	@Override
	public void display() {
		button.setVisible(true);
	}

	@Override
	public void close() {
		button.setVisible(false);
	}

	/**
	 * @return the button
	 */
	public JButton getButton() {
		return button;
	}

	/**
	 * @param button
	 *            the button to set
	 */
	public void setButton(JButton button) {
		this.button = button;
	}

	@Override
	public void positionChanged(PositionChangedEvent event) {
		piecePosition = event.getNewPiecePosition();

	}

	

}
